package me.pcqpcq.android.aclean;

import me.pcqpcq.android.Constant;
import me.pcqpcq.android.aclean.R;
import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;

public class SettingCleanActivity extends PreferenceActivity implements OnPreferenceClickListener {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 设置配置文件名称
		getPreferenceManager().setSharedPreferencesName(Constant.PREFERENCE_CLEAN_LIST);
		// 初始化配置文件
		addPreferencesFromResource(R.layout.act_preferences);
		
		// 设置黑名单监听器
		PreferenceScreen pickBlackList =
				(PreferenceScreen) getPreferenceManager().findPreference(getString(R.string.key_black_list_mgr));
		pickBlackList.setOnPreferenceClickListener(this);
		// 设置APK清理目录监听器
		PreferenceScreen pickApkDirs =
				(PreferenceScreen) getPreferenceManager().findPreference(getString(R.string.key_apk_dirs));
		pickApkDirs.setOnPreferenceClickListener(this);
	}

	@Override
	public boolean onPreferenceClick(Preference preference) {
		Intent intent = new Intent();
		
		// 垃圾清理黑名单
		if (preference.getKey().equals(getString(R.string.key_black_list_mgr))) {
			intent.setClass(SettingCleanActivity.this, BlackListActivity.class);
			startActivity(intent);
		}
		
		// APK清理
		if (preference.getKey().equals(getString(R.string.key_apk_dirs))) {
			intent.setClass(SettingCleanActivity.this, ApkDirsActivity.class);
			startActivityForResult(intent, Constant.RESULT_CODE_PICK_DIR);
		}

		return false;
	}

}
